<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<title>查询统计管理</title>
<meta name="decorator" content="default"/>
<script src="${ctxStatic}/common/change/change.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		initVaccName(inventoryDetail.companyCode,inventoryDetail.vaccineId);
		initVaccCompanyName(inventoryDetail.companyCode);
		$(".vaccineCompany").change(function(){
			var vaccId = $(this).val();
			initCompanyName($(this).val());
			if(vaccId == ""){
				initVaccCompanyName("");
			}
		});
		$(document).on("click","#btnPrint",function(){
			var arr=new Array();  
			$('input[name="grade"]:checked').each(function(){  
			    arr.push($(this).val());//向数组中添加元素  
			});  
			var grade=arr.join(',');//将数组元素连接起来以构建一个字符串  
			window.open("${ctx}/area/vaccinate/printOrderDetailListReport?storeCode="+$("#storeCodeId").val()+"&grade="+grade+"&storeName="+$("#storeCodeName").val()
					+"&cType=${inventoryDetail.cType}&vaccineId=${inventoryDetail.vaccineId}"+"&companyCode=${inventoryDetail.companyCode}"
					+"&orderType=${inventoryDetail.orderType}&orderStatus=${inventoryDetail.orderStatus}&beginDate="+$("#beginDate").val()
					+"&endDate="+$("#endDate").val()+"&batchNo="+$("#batchNo").val()+"&orderNo="+$("#orderNo").val()
					+"&pageSize="+$("#pageSize").val()+"&pageNo="+$("#pageNo").val(), "_blank");
		});
		$(document).on("click","#btnReset",function(){
			$("#orderStatus").val("").select2();
			$("#cType").val("").select2();
			$("#vaccineId").val("").select2();
			$("#companyCode").val("").select2();
			$("#orderType").val("").select2();
			$("#beginDate").val("");
			$("#endDate").val("");
			$("#orderNo").val("");
			$("#batchNo").val("");
			$("#storeCodeId").val("");
			$("#storeCodeName").val("");
			$("#grade").val("");
		});
		$('#orderStatus').val("${inventoryDetail.orderStatus}".split(','));
		$('#orderStatus').trigger('change.select2');
	});
	var inventoryDetail = JSON.parse('${fns:toJson(inventoryDetail)}');
	function page(n,s){
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
    	return false;
    }
	function down(){
		top.$.jBox.confirm("确认要导出出入库明细信息数据吗？","系统提示",function(v,h,f){
			if(v=="ok"){
				$("#searchForm").attr("action","${ctx}/area/vaccinate/exportArea");
				$("#searchForm").submit();
			}
			$("#searchForm").attr("action","${ctx}/area/vaccinate/queryOrderDetailList");
		},{buttonsFocus:1});
		top.$('.jbox-body .jbox-icon').css('top','55px');
	}
	function downSell(){
		var pageNo = $("#pageNo").val();
		var pageSize = $("#pageSize").val();
		top.$.jBox.confirm("确认要导出销售发票吗？","系统提示",function(v,h,f){
			if(v=="ok"){
				$("#searchForm").attr("action","${ctx}/area/vaccinate/exportSell");
				$("#pageNo").val(1);
				$("#pageSize").val(-1);
				$("#searchForm").submit();
			}
			$("#pageNo").val(pageNo);
			$("#pageSize").val(pageSize);
			$("#searchForm").attr("action","${ctx}/area/vaccinate/queryOrderDetailList");
		},{buttonsFocus:1});
		top.$('.jbox-body .jbox-icon').css('top','55px');
	}
	
	function vaccCount(){
		var pageNo = $("#pageNo").val();
		var pageSize = $("#pageSize").val();
		top.$.jBox.confirm("确认要导出疫苗统计吗？","系统提示",function(v,h,f){
			if(v=="ok"){
				$("#searchForm").attr("action","${ctx}/area/vaccinate/vaccCountExport");
				$("#pageNo").val(1);
				$("#pageSize").val(-1);
				$("#searchForm").submit();
			}
			$("#pageNo").val(pageNo);
			$("#pageSize").val(pageSize);
			$("#searchForm").attr("action","${ctx}/area/vaccinate/queryOrderDetailList");
		},{buttonsFocus:1});
		top.$('.jbox-body .jbox-icon').css('top','55px');
	}
</script>
<style type="text/css">
	.minWidth {
		min-width: 177px;
	}
	.autoWidth {
	    width: auto;
	}	
	.select2-choices{
	    border-radius: 4px;
	}	
	#contentTable td ,#contentTable th{
		text-align: center;
		padding: 1px 2px;
	}
	#contentTable tbody tr td{
		font-size: 13px;
	}
</style>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="#">分地区出入库明细查询</a></li>
	
	</ul>
	<form:form id="searchForm" modelAttribute="inventoryDetail" action="${ctx}/area/vaccinate/queryOrderDetailList" method="post" class="form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<div class="breadcrumb">
			<table class="table table-bordered">
				<tr>
				    <th>地区</th>
					<td>
						<sys:treeselect2 id="storeCode" name="storeCode" value="${inventoryDetail.storeCode}" labelName="storeName" labelValue="${inventoryDetail.storeName}"
					    title="机构" url="/sys/office/treeData" cssClass="input-medium" layer = "true" disabled="${office.grade == '50' ? 'disabled' : 'false'}"/>
					</td>
					<th>查询范围</th>
					<td>
						<form:checkboxes path="grade" items="${fns:getDictList('sys_office_grade_3')}" values="${inventoryDetail.grade}" itemLabel="label" itemValue="value"/>
					</td>
					<th>批号</th>
					<td>
						<form:input path="batchNo" id="batchNo" class="span2 minWidth"/>
					</td>
				</tr>
				<tr>
				    <th>疫苗属性</th>
					<td>
						<form:select path="cType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('bs_vaccineInfo_type')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
				    <th>疫苗名称:</th>
					<td>
						<form:select path="vaccineId" id="vaccineId" class="span2 minWidth vaccineCompany" >
							<form:option value="" label="--请选择--"/>
						</form:select>
					</td>
					<th>生产企业：</th>
					<td>
						<form:select path="companyCode" id="companyCode" class="span2 minWidth changeCompany vaccCompanyName">
						    <form:option value="" label="--请选择--"/> 
						</form:select>
					</td>
				</tr>
				<tr>
					<th>出入库起始日期</th>
					<td>
						<input name="beginDate" id ="beginDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${inventoryDetail.beginDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</td>
					<th>出入库截止日期</th>
					<td>
						<input name="endDate" id ="endDate" type="text" readonly="readonly" maxlength="20" class="input-medium Wdate"
							value="<fmt:formatDate value="${inventoryDetail.endDate}" pattern="yyyy-MM-dd"/>"
							onclick="WdatePicker({dateFmt:'yyyy-MM-dd',isShowClear:false});"/>
					</td>
					<th>出入库单号</th>
					<td>
						<form:input path="orderNo" id="orderNo" class="span2 minWidth"/>
					</td>
				</tr>
				<tr>  
				    <th>出入库类型</th>
					<td>
						<form:select path="orderType" class="span2 minWidth">
							<form:option value="" label="--请选择--"/>
							<form:options items="${fns:getDictList('bs_order_ordertype')}" itemLabel="label" itemValue="value" htmlEscape="false"/>
						</form:select>
					</td>
					<th>出入库状态</th>
					<td  colspan="3">
						<form:select path="orderStatus" items="${fns:getDictList('bs_order_status')}"
							itemLabel="label" itemValue="value" class="span2 minWidth autoWidth"  multiple="true">
						</form:select>
					</td>
				</tr>
			</table>
			<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>
			<input id="btnReset" type="button" class="btn btn-primary" value="重置"/>
			<input onclick="down()" class="btn btn-primary" type="button" value="导出"/>
			<input id="btnPrint" class="btn btn-primary" type="button" value="打印"/>
			<c:if test="${showSell == true}">
			    <input onclick="downSell()" class="btn btn-primary" type="button" value="销售发票"/>
			    <!-- <input onclick="vaccCount()" class="btn btn-primary" type="button" value="疫苗统计"/> -->
			</c:if>
			<div class="pull-right">
				<span style = "font-size: 16px;text-align: center;">成本总金额：${mapSum.orignPriceSum }	&nbsp;/	&nbsp;售价总金额：${mapSum.sellPriceSum }	&nbsp;/	&nbsp;总数量：${mapSum.vaccNum } &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>
			</div>
		</div>
	</form:form>
	<sys:message content="${message}"/>
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
			    <th>编号</th>
				<th>疫苗名称</th>
				<th>生产企业</th>
				<th>规格</th>
				<th>批号</th>
				<th>疫苗属性</th>
				<th>出入库日期</th>
				<th>有效期</th>
				<th>出入库单号</th>
				<th>出入库类型</th>
				<th>供货单位</th>
				<th>收货单位</th>
				<th>成本价</th>
				<th>出售价</th>
				<th>数量(支或粒)</th>
				<th>金额</th>
			</tr>
		</thead>
		<tbody>
		<c:forEach items="${page.list}" var="details" begin="0" varStatus="status">
			<tr>
			    <td>
			        ${(page.pageNo-1)*page.pageSize+status.index+1 }
			    </td>
				<td>
				    ${details.vaccName}
				</td>
				<td>
				    ${details.companyName}
				</td>
				<td>
				    <c:if test="${details.batchType eq '2' }">
						${fns:getDictLabel(details.spec, 'syringe_spec', '') }
					</c:if>
					<c:if test="${details.batchType eq '1' }">
                        ${details.dose},${details.doseType}<br>
                        ${details.spec},${details.containerType}
					</c:if>
				</td>
				<td>
				    ${details.batchNo}
					<c:if test="${not empty details.secondBatchno}">
				        <span title="(查询批号时不需要带入亚批号)" style="color: #2fa4e7;">-${details.secondBatchno}</span>
				    </c:if>
				</td>
				<td>
				    ${fns:getDictLabel(details.cType, 'bs_vaccine_type', '') }
				</td>
				<td>
				    <fmt:formatDate value="${details.inAndOutDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
				    <fmt:formatDate value="${details.outBoundDate}" pattern="yyyy-MM-dd"/>
				</td>
				<td>
				    ${details.orderNo}
				</td>
				<td>
				    ${fns:getDictLabel(details.orderType,'bs_order_ordertype','')} / ${fns:getDictLabel(details.orderStatus, 'bs_order_status', '') }
				</td>
				<td>
				    ${details.supplyorgName}
				</td>
				<td>
				    ${details.receiveorgName}
				</td>
				<td style = "text-align: right; padding-right: 10px">
				         ￥${details.orignprice}
				</td>
				<td style = "text-align: right; padding-right: 10px">
				         ￥${details.sellprice}
				</td>
				<td>
				    ${details.vaccNum}
				</td>
				<td style = "text-align: right; padding-right: 10px">
				    ￥${details.vaccNumAmount}
				</td>
			</tr>
		</c:forEach>
		</tbody>
	</table>
	<div class="pagination">${page}</div>
</body>
</html>